<!-- 修改记工 -->
<template>
	<view class="page">
		<view class="content p-3">
			<view class="bt-block">
				<bg-cell2 valueColor='#4e5969' label="项目名称" :value="postData.projectName"></bg-cell2>
				<bg-cell2 valueColor='#4e5969' label="项目地址" :value="postData.projectAddr"></bg-cell2>
				<bg-cell2 valueColor='#4e5969' label="考勤日期" :value="postData.createTime"></bg-cell2>
				<bg-cell2 valueColor='#4e5969' :border="false" label="考勤员" :value="postData.recordUserName"></bg-cell2>
			</view>
		</view>
		<view class="bt-block mx-3 px-2">
			<u--form errorType="toast" labelWidth="80" :labelStyle="{ fontSize: '28rpx' }" labelPosition="left"
				:model="item" :rules="rules" ref="uForm">

				<u-form-item labelPosition="left" required label="工种" prop="workJobType">
					<view class="form-block">
						<bg-label :options="workJobs" :value="postData.workJobType"></bg-label>
					</view>
				</u-form-item>
				<u-form-item labelPosition="left" required label="工人姓名">
					<view class="form-block">
						<!-- <view>{{ nameStr }}</view> -->
						<view>{{ item.userName }}</view>
					</view>
				</u-form-item>
				<view class="bt-line-1"> </view>
				<u-form-item labelPosition="left" required label="工作性质" prop="workType">
					<view class="form-block">
						<!-- <bg-select :value.sync="item.workType" :columns="dict.type.work_type"
							key="workType"></bg-select> -->
							<bg-select v-if="item.salaryType==1" :value.sync="item.workType" :columns="dict.type.work_type"
							key="workType"></bg-select>
							<bg-select v-else :value.sync="item.workType" :columns="workTypeOptions"
							key="workType"></bg-select>
					</view>
				</u-form-item>
				<view class="bt-line-1"> </view>

				<u-form-item labelPosition="left" required label="工时设定" prop="workingHours">
					<view class="form-block">
						<u-number-box :min="0.5" v-model="item.workingHours" :step="0.5" :max="10"></u-number-box>
					</view>
				</u-form-item>

			</u--form>
		</view>
		<view class="bt-footer">
			<bg-btn @click="saveData">确认修改</bg-btn>
		</view>
	</view>
</template>

<script>
import { workTypes } from '@/utils/constant'
import { editAttend, getAttend, checkAttend, editWorkHours } from "@/api/attend.js"
export default {
	dicts: ['work_type'],
	onLoad(options) {
		const eventChannel = this.getOpenerEventChannel();
		this.eventChannel = eventChannel
		eventChannel.on('acceptDataFromOpenerPage', ({ obj, item }) => {
			this.postData = obj
			this.item = item
		})

	},
	mounted() {
		uni.$on('selected-users', (e) => {
			this.selectedUsers = e
			this.postData.userIds = this.selectedUsers.map(u => u.userId)
		})
		this.$store.dispatch("types/getJobs").then(res => {
			console.log('res', JSON.stringify(res));

			this.workJobs = res

		})
	},
	computed: {
		nameStr() {
			if (this.postData && this.postData.userList) {
				return this.postData.userList.map(u => u.userName).join(',')
			}
			// 只展示跳转进来的用户名称
		}
	},
	data() {
		return {
			eventChannel: null,
			workMoney: {},
			serialId: '',
			workJobs: [],
			selectedUsers: [],
			item: {},
			postData: {

			},
			rules: {

			},
			workTypeOptions:[{label:'月工',value:1},{label:'加班',value:2}]

		}
	},
	methods: {
		getData() {
			getAttend(this.serialId).then(res => {
				this.postData = res.data
			})
		},
		selectUsers() {
			uni.navigateTo({
				url: "/pages/common/user-select/multi-select"
			})
		},
		removeUsers(idx) {
			this.selectedUsers.splice(idx, 1)
			this.postData.userIds = this.selectedUsers.map(u => u.userId)
		},
		async saveData() {
			if (this.item.workingHours <= 0) {
				this.$modal.msg("请输入正确的工时")
				return false
			}//todo
			// console.log('item',JSON.stringify(this.item));
			// return
			// this.item.workJobType = this.postData.workJobType
			// let obj = {
			// 	id: this.item.attendanceId,
			// 	workHours: this.item.workHours,
			// 	workType: this.item.workType,
			// }
			// editWorkHours(obj).then(res => {
			// 	this.$modal.msg("修改成功")
			// 	this.eventChannel.emit("acceptDataFromOpenedPage", this.item)
			// 	this.$tab.navigateBackDelay()
			// })
			this.eventChannel.emit("acceptDataFromOpenedPage", this.item)
			this.$tab.navigateBackDelay()
		},

	}
}
</script>

<style scoped>
.page {
	padding-bottom: 180rpx;
}
</style>
